package k.daniel.util;
import org.junit.Test;

import java.util.Calendar;
import java.util.Date;

import static org.junit.Assert.assertEquals;

public class DateFormatUtilTest {
    long time = Calendar.getInstance().getTimeInMillis();
    Date date=new Date(time);
    String timeToString=DateFormatUtil.timeToString(time, DateFormatUtil.FORMAT_DATE_TIME);
    @Test
    public void testStringToTime() {
        assertEquals(time/1000,DateFormatUtil.stringToTime(timeToString, DateFormatUtil.FORMAT_DATE_TIME)/1000);
    }
    @Test
    public void testTimeToString() {
        assertEquals(timeToString, DateFormatUtil.timeToString(time,DateFormatUtil.FORMAT_DATE_TIME));
    }
    @Test
    public void testStringToDate() {
        //毫秒值转换后为000，所以需要去掉末尾的值
        assertEquals(date.getTime()/1000,DateFormatUtil.stringToDate(timeToString,DateFormatUtil.FORMAT_DATE_TIME).getTime()/1000);
    }



}
